using UnityEngine;
using System.Collections;

public class ScrollingBackground : MonoBehaviour
{
	static public float sSpeed = 60.0f;
	
	
	private bool mHaveSpawnedFollowing = false;
	
	// Use this for initialization
	void Start () 
	{
		
	}
	
	// Update is called once per frame
	void Update () 
	{
		transform.position -= Vector3.right * sSpeed * Time.deltaTime;
		
		if(transform.position.x < 0 && !mHaveSpawnedFollowing)
		{
			float lX = transform.position.x + renderer.bounds.size.x;
			
			GameObject lObj = Instantiate(gameObject, new Vector3(lX, transform.position.y, transform.position.z), transform.rotation) as GameObject;
			
			mHaveSpawnedFollowing = true;
		}
	}
	
	void OnBecameInvisible()
	{
		if(transform.position.x < 0)
			Destroy(gameObject);
	}
}
